#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：partial_codes-master 
@File ：message_handler.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/2/23 23:47 
"""

"""
报文接收模块
"""

import socket

HOST = '127.0.0.1'
PORT = 65432


def parse_type(message):
	"""
	解析报文类型
	"""
	# 报文类型解析逻辑
	return "A"


def process_message(message):
	"""
	解析并处理接收到的报文
	"""
	# 报文解析逻辑
	msg_type = parse_type(message)
	if msg_type == "A":
		print("A")
	# 处理A类型报文的逻辑
	elif msg_type == "B":
		print("B")


# 处理B类型报文的逻辑

# 更多类型判断逻辑


with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
	s.bind((HOST, PORT))
	s.listen()
	conn, addr = s.accept()
	with conn:
		print(f'Connected by {addr}')
		while True:
			data = conn.recv(1024)
			if not data:
				break
			# 处理接收到的数据
			process_message(data)
